package com.ayou.eggguard.farm.mapper;

import com.ayou.eggguard.farm.pojo.ChickenCoop;
import com.ayou.eggguard.farm.pojo.FeedRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ChickenCoopMapper {

    @Select("select * from chickencoop where coop_number=#{coopNumber}")
    ChickenCoop getCoopByNumber(String coopNumber);

    @Insert("insert into chickencoop(farm_id, coop_number, capacity, current_stock, chicken_breed, birthday) " +
            "values(#{farmIdByFarmName},#{chickenCoop.coopNumber},#{chickenCoop.capacity},#{chickenCoop.currentStock},#{chickenCoop.chickenBreed},#{chickenCoop.birthday}) ")
    void addCoop(@Param("farmIdByFarmName") int farmIdByFarmName, @Param("chickenCoop") ChickenCoop chickenCoop);

    @Update("update chickencoop set capacity=#{capacity},current_stock=#{currentStock}," +
            "chicken_breed=#{chickenBreed},birthday=#{birthday} where coop_number=#{coopNumber}")
    void updateCoopInfo(ChickenCoop chickenCoop);

    @Select("select * from chickencoop where chickencoop.farm_id =" +
            "(select chickenfarm.farm_id from chickenfarm where farm_name=#{farmName});")
    List<ChickenCoop> getCoopsByFarmName(String farmName);

    @Delete("delete from chickencoop where coop_number=#{coopNumber}")
    void deleteCoop(String coopNumber);

    @Select("select * from feedrecord where coop_Number=" +
            "(select chickencoop.coop_id from chickencoop where coop_number=#{coopNumber})")
    List<FeedRecord> getFeedRecord(String coopNumber);
}
